const Core = require('@alicloud/pop-core');

const db = require('../sql/db.js');

var client = new Core({
    accessKeyId: 'LTAI5tELA8Avci1BLtC7H1zi',
    accessKeySecret: 'MjqWg1bItQnaqga2YH77BOOF9xh1Xh',
  // securityToken: '<your-sts-token>', // use STS Token
  endpoint: 'https://iot.cn-shanghai.aliyuncs.com',
  apiVersion: '2018-01-20'
});

var params = {
  "IotInstanceId": "iot-06z00b21oxo03w6",
  "ProductKey": "gr8mWvG2ZTO",
  "DeviceName": "device7"
}

var requestOption = {
  method: 'POST'
};

client.request('DeleteDevice', params, requestOption).then((result) => {
  console.log(JSON.stringify(result));


  //数据库删除设备
  db(`delete from sensor where SensorName='${params.DeviceName}'`, (err, result) => {
    if (err) throw err;
    console.log('删除设备成功');
  })
  
}, (ex) => {
  console.log(ex);
})